<?
if($_POST["do"]=="removehotfix"){

	echo "<div id=\"info\">";
	foreach($_POST[hotfix] as $value){
		system("patch -F6 -p0 -R -f --posix -i data/hotfix/$value");
		unlink("data/hotfix/$value");
		echo "$value removed successfully<br/>";
	}
}
if($_POST['do']=="hotfix"){
	$uFile=$_FILES[datei][name];
	if(file_exists("data/hotfix/$uFile")){
		echo "<div class=\"error\">The Hotfix is allready installed</div>";
	}else{
	    move_uploaded_file($_FILES[datei][tmp_name], "data/hotfix/$uFile");
        echo "installing data/hotfix/$uFile";
		system("patch -F6 --verbose -p0 -f -i data/hotfix/$uFile", $return);
        if($return>0){
            echo "<div class=\"error\">Something went wrong :( Hotfix could not be applied.</div>";
            unlink("data/hotfix/$uFile");
        }
    }
}

//load installed hotfixes
$dir="data/hotfix/";
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if( filetype($dir . $file)!="dir") {
				$hotfix[]=$file;
			}
        }
        closedir($dh);
    }
}

?>
<fieldset>
  <legend>Hotfix</legend>
    <b>Installed Hotfixes:</b><br>
    <form action="index.php" method="post">
		<input type="hidden" name="do" value="removehotfix" />
		<?
		if(count($hotfix)>0){
			foreach($hotfix as $value){
				echo "<input type=\"checkbox\" name=\"hotfix[]\" value=\"$value\" /> $value<br/>";
			}
			echo "<input type=\"submit\" value=\"remove\" />";
		}else{
			echo "none<br>";
		}
	?>
	</form>
	<br/>
	<br/>
	<form action="index.php" method="post" enctype="multipart/form-data" onsubmit="confirm('sDo you realy want to apply hotfix?');">
	<input type="hidden" name="do" value="hotfix" />
	Apply new Hotfix:
	<input name="datei" type="file" size="10" maxlength="100000" onchange="this.form.submit();"/>
  </form>
</fieldset>

